package xing.application.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import xing.application.api.client.PmsClient;

import java.net.URLEncoder;
import java.text.MessageFormat;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2017-11-06 16:26
 * @Description:业主报事and智能管家混合功能
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         ------------------------  
 * 1.0      2017/11/6     dst                               
 *******************************************************************************************
 */
@Service
public class OwnerRequireAndAiApi {
    @Autowired
    PmsClient pmsClient;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * @Description:报事智能管家列表
     * @param:   * @param null
     * @Author: dustin
     * @Date: 2017-11-06 16:32
     */
    public String getRequireAndAiList(String phone,int pageNo,int pageSize,String searchText,String searchType,String compositeName,String compositeType) throws Exception{
//searchText=%E6%BC%95%E6%B2%B3%E6%B3%BE&searchType=finished&compositeName=startTime&compositeType=desc
        String para= MessageFormat.format("phoneNum={0}&pageNo={1}&pageSize={2}",phone,pageNo,pageSize);
        if(!StringUtils.isEmpty(searchText))
            para=para+"&searchText="+ URLEncoder.encode(searchText,"UTF-8");
        if(!StringUtils.isEmpty(searchType))
            para=para+"&searchType="+ searchType;
        if(!StringUtils.isEmpty(compositeName))
            para=para+"&compositeName="+compositeName;
        if(!StringUtils.isEmpty(compositeType))
            para=para+"&compositeType="+compositeType;
//        String str= pmsClient.getCommand("wxapi/getTeventList",
//                MessageFormat.format("phoneNum={0}&pageNo={1}&pageSize={2}&searchText={3}&searchType={4}&compositeName={5}&compositeType={6}",
//                        phone,pageNo,pageSize,searchText,compositeName,compositeType));

        String str= pmsClient.getCommand("wxapi/getEventList", para);
        return str;
    }

    /**
     * @Description:获取状态数量
     * @param:  * @param null
     * @Author: dustin
     * @Date: 2017-10-19
     */
    public String getStatusCount(String phone){
        String str= pmsClient.getCommand("wxapi/getEventCount",
                MessageFormat.format("phoneNum={0}",phone));
        return str;
    }
    /**
     * @Description:获取未读消息数
     * @param:   * @param null
     * @Author: dustin
     * @Date: 2017-11-06 17:57
     */
    public String getUnReadMsgCount(String phone){
        String str= pmsClient.getCommand("wxapi/getNoReadMsgNum",
                MessageFormat.format("phoneNum={0}",phone));
        return str;
    }
}
